Geographic data and visualization

GEOG 30323

November 15, 2016

What is geographic data?

  • Thus far: we’ve been working with data (largely) in tabular data frames, where each column represents data “attributes”
  • Geographic data: includes information on location - specifically, where the observation is located on the Earth’s surface

Maps!

Longitude and latitude: the basics

Geographic coordinates

  • Longitude (X) and latitude (Y) coordinates can be expressed as:
  • Degrees minutes seconds (e.g. \(97^{\circ}21'37''W\), \(32^{\circ}42'38''N\))
  • Decimal degrees (e.g. \(-97.36\), \(32.71\))

Conversion between DMS and decimal degrees:

\[DD = D + \frac{M}{60} + \frac{S}{3600}\]

Coordinate systems

  • Geographic coordinate system: coordinate system based on latitude and longitude (coordinates on a sphere)
  • Projected coordinate system: coordinate system projected onto a two-dimensional surface (coordinates on a plane)
  • Example: http://bl.ocks.org/mbostock/raw/5731632

Map projections

Original source: Mike Bostock

Tiled mapping and Web Mercator

Map projections and distortion

Examples:

Vector data

Raster data

Vector data: CSV files

Let’s make a map!

Mapping point data

Vector data: the shapefile

  • Shapefile: common format for encoding vector geographic data
  • Three required files: .shp, .dbf, and .shx; .prj recommended

Vector data: GeoJSON

Mapping polygons

Should you map?

  • Beware the “amazing map”…
Source: Clickhole (The Onion)

Maps vs. charts

  • For discussion: which visualization is more effective for showing differences in our data?

Chart for comparison

Code to reproduce the chart

import pandas as pd, seaborn as sns, matplotlib.pyplot as plt
sns.set(style="whitegrid")
df = pd.read_csv("http://personal.tcu.edu/kylewalker/mexico.csv")

plt.figure(figsize = (10, 8))

p = sns.stripplot(data = df.sort_values('pri10', ascending = False), 
                  x = 'pri10', y = 'name', palette = "RdPu_d", 
                  orient = 'h', size = 8)
p.set(xlabel = "% of workforce in primary sector", 
      xlim = (0, 50), ylabel = "")
p.axes.xaxis.grid(False)
p.axes.yaxis.grid(True)
sns.despine(left = True, bottom = True)